package zj.com.fragments;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import zj.com.activities.DqrEditActivity;
import zj.com.activities.DqrJcxDetailActivity;
import zj.com.adapter.DqrJcxAdapter;
import zj.com.adapter.JcxAdapter;
import zj.com.app.ZjApplication;
import zj.com.model.DjcModel;
import zj.com.model.JcdInfoDB;
import zj.com.model.JcxDB;
import zj.com.model.UserInfo;
import zj.com.net.NetManager;
import zj.com.net.OnResponseListener;
import zj.com.util.DialogUtil;
import zj.com.zj.R;

/**
 * Created by xi on 16/6/4.
 * 检查项
 */
public class DqrJcxFragment extends Fragment {


    public ListView listView;
    public List<JcxDB> list;
    public DqrJcxAdapter adapter;
    public Intent intent;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_dqr_jcx, container, false);
        initView(view);
        initData();

        return view;
    }


    public void initView(View view){

        listView = (ListView) view.findViewById(R.id.listView);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                intent = new Intent(getActivity(), DqrJcxDetailActivity.class);
                intent.putExtra("detail", list.get(position));
                startActivity(intent);
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();

       JcdInfoDB jcd =  ZjApplication.dqrJcdInfo;
        if(jcd != null && jcd.getJcxDBList() != null){
            adapter.setDataChange(jcd.getJcxDBList());
        }
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        if(isVisibleToUser){
            JcdInfoDB jcd =  ZjApplication.dqrJcdInfo;
            if(jcd != null && jcd.getJcxDBList() != null){
                this.list = jcd.getJcxDBList();
                adapter.setDataChange(jcd.getJcxDBList());
            }
        }
        super.setUserVisibleHint(isVisibleToUser);
    }

    public void initData(){
        list = new ArrayList<JcxDB>();
        adapter = new DqrJcxAdapter(list,getActivity());
        listView.setAdapter(adapter);

    }



}
